package zjy;

public class Person {
    private String name;
    protected String sex;
    int years;

    public Person(String name, String sex, int years) {
        if ((sex.equals("男") || sex.equals("女")) && ((years > 0) && (years < 130))) {
            this.name = name;
            this.sex = sex;
            this.years = years;
        } else
            System.out.println("年龄错误");
    }

    public Person() {
        this.name = "";
        this.sex = "";
        this.years = 0;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getYears() {
        return years;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", years=" + years +
                '}';
    }

    public void setYears(int years) {
        this.years = years;

    }
}

